package com.service.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.dao.ProductBigCategoryDao;
import com.entity.ProductBigCategory;
import com.entity.ProductSmallCategory;
import com.service.ProductBigCategoryService;
import com.sqlSessionFactory.SqlSessionFactoryUtil;

public class ProductBigCategoryServiceImpl implements ProductBigCategoryService {

	@Override
	public List<ProductBigCategory> queryAllProductBigCategory() {
		SqlSession sqlSession = SqlSessionFactoryUtil.getSqlSession();
		ProductBigCategoryDao productBigCategoryDao = sqlSession.getMapper(ProductBigCategoryDao.class);
		List<ProductBigCategory> listProductBigCategory = productBigCategoryDao.queryAllProductBigCategory();
		sqlSession.close();
		return listProductBigCategory;
	}

	@Override
	public List<ProductBigCategory> queryProductBigSmallCategory() {
		SqlSession sqlSession = SqlSessionFactoryUtil.getSqlSession();
		ProductBigCategoryDao productBigCategoryDao = sqlSession.getMapper(ProductBigCategoryDao.class);
		List<ProductBigCategory> listProductBigCategory = productBigCategoryDao.queryProductBigSmallCategory();
		for(ProductBigCategory p : listProductBigCategory) {
			System.out.println(p.getBpid()+" "+p.getType());
			List<ProductSmallCategory> listProductSmallCategory = p.getListProductSmallCategory();
			for(ProductSmallCategory ps :listProductSmallCategory) {
				System.out.println(ps.getSpid()+"  "+ps.getSpname());
			}
		}
		//sqlSession.commit();
		sqlSession.close();
		return listProductBigCategory;
	}

}
